using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace BuildingBlocks.Infrastructure.Inbox;

public sealed class InboxMessageConfiguration : IEntityTypeConfiguration<InboxMessage>
{
    public void Configure(EntityTypeBuilder<InboxMessage> builder)
    {
        builder.ToTable("inbox_messages");

        builder.HasKey(i => i.Id);

        builder.Property(i => i.Type).HasMaxLength(255).IsRequired();
        builder.Property(i => i.Content).IsRequired();
        builder.Property(i => i.OccurredOnUtc).IsRequired();
        builder.Property(i => i.ProcessedOnUtc);
        builder.Property(i => i.Error);

        builder.HasIndex(i => i.ProcessedOnUtc);
        builder.HasIndex(i => new { i.Id, i.ProcessedOnUtc });
    }
}
